﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WxMenu.aspx.cs" Inherits="bianzhuo.SupportPlatform.BzBusiness.WxMenu" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>微信菜单管理</title>
    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="js/tdcolor.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <link href="css/style.css" rel="stylesheet" type="text/css" />

</head>
<body>
    <form id="form1" runat="server">
        <div class="content">
            <ul class="breadcrumb">
                <%if (Request.Cookies["BzSupport_Business"] != null)
                  {
                %>
                <li><a href="BusinessHome.Aspx?MicroId=<%= Request.Cookies["BzSupport_Business"].Values["WxID"] %>">首页</a> <span class="divider">/</span></li>
                <%} %>
                <li class="active">微信菜单</li>
            </ul>
            <div class="container">
                <div>

                    <table class="user_list" border="0" cellspacing="0" cellpadding="0">
                        <thead>
                            <tr>
                                <th width="8%" class="border_left">排序</th>
                                <th width="30%">主菜单名称</th>
                                <th width="32%" align="center">触发关键词或url</th>
                                <th width="6%" align="center">启用</th>
                                <th width="10%" align="center">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <asp:Repeater ID="Repeater1" runat="server">
                                <ItemTemplate>
                                    <tr class="td25">
                                        <td <%# Convert.ToBoolean(Eval("IsMain"))?"align='center' class='border_left borml'":"class='border_left'"%>>
                                            <input name='MenuId' type='hidden' value="<%#Eval("WxMenuID")%>" /><input name='MenuParentID' type='hidden' value="<%#Eval("MainMenuID")%>" /><input name="MenuIndex" type="text" size="2" value="<%#Eval("OrderDesc") %>" class="input_text13 <%#Convert.ToBoolean(Eval("IsMain"))?"":"wxinput_ml"%>"></td>
                                        <td>
                                            <input name="MenuName" type="text" size="15" style="<%#Convert.ToBoolean(Eval("IsMain"))?"":"margin-left:50px;"%>" class="input_text14 <%#Convert.ToBoolean(Eval("IsMain"))?"":"wxinput_m2"%>" value="<%#Eval("MenuName")%>"><%#Convert.ToBoolean(Eval("IsMain"))?"<a href='javascript:;' class='btn_small btn-01 btnAddSubMenu' data-id='" +Eval("WxMenuID").ToString() +"'>+子栏目</a>":""%></td>
                                        <td align="left">&nbsp;&nbsp;<select name="MenuLinkUrl" class="btn"><%#GetMenuType(Eval("MenuType"))%></select>
                                            <input name="MenuWord" type="text" size="15" class="input_text14 wxinput_m2" value="<%#Eval("WordKey")%>" style="<%#(Convert.ToInt32(Eval("MenuType"))>0)?"display:none": ""%>" /></td>
                                        <td align="center">
                                            <input name="MenuAbled" type="checkbox" value="1" <%#Convert.ToBoolean(Eval("IsPubit"))==true?"checked='checked'":""%> /><input name="MenuAbled" type="checkbox" value="0" <%#Convert.ToBoolean(Eval("IsPubit"))==false?"checked='checked'":""%> style="display: none" /></td>
                                        <td height="30" align="center"><a href="javascript:;" class="btn_small btndelete" data-id="<%#Eval("WxMenuID")%>">删除</a></td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td height="36" colspan="2" align="left" class="border_left"><a href="javascript:;" id="AddMainMenu" class="btn_small btn-01">+主栏目</a></td>
                                <td height="36" colspan="3" align="right">
                                    <button name="saveall" type="submit" class="btn btn-01">保存全部</button>&nbsp;&nbsp;&nbsp;
                                    <button type="submit" name="createwxmenu" class="btn btn-02" title="保存后生成微信菜单，同步到微信公众平台">生成微信菜单</button>&nbsp;&nbsp;&nbsp;
                                    <button name="deletewxmenu" type="submit" class="btn" title="删除目前微信已存在菜单">删除微信菜单</button></td>
                            </tr>
                        </tfoot>
                    </table>
                </div>

            </div>
    </form>
    <script>
        //删除菜单   
        $('.btndelete').off().on('click', function () {
            if (confirm('确定要删除菜单吗') == false) {
                return false;
            }
            var index = $('.btndelete').index($(this));

            $('tbody tr').eq(index).remove();
            var id = $(this).attr('data-id');
            if (id > 0) {
                $.get('?delete=' + id, function (data) {
                    alert(data);
                })
            }
        });

        //创建下属菜单项目
        $('.btnAddSubMenu').click(function () {

            var url = '?create=' + $(this).attr('data-id') + '&MicroId=' + getName('MicroId');
            $.post(url, { t: new Date() }, function (data) {
                $('[name=saveall]').click();
            })

        })

        //创建主菜单项目
        $('#AddMainMenu').click(function () {
            var url = '?create=' + $(this).attr('data-id') + "&isMain=1" + '&MicroId=' + getName('MicroId');
            $.post(url, { t: new Date() }, function (data) {
                $('[name=saveall]').click();
            })

        })

        //根据菜单链接下拉变换自定义地址输入框
        $('[name=MenuLinkUrl]').change(function () {
            if ($(this).val() > 0) {
                $(this).next('[name=MenuWord]').hide();

            } else {
                $(this).next('[name=MenuWord]').show();
            }

        });
        //启用状态切换
        $('[name=MenuAbled][value=1]').click(function () {
            $(this).next('[name=MenuAbled]').attr("checked", !$(this).attr("checked"));
        })

        $('[name=MenuName]').each(function () {
            if ($(this).next('.tips').length == 0) {
                $(this).after("<span class='tips'>&nbsp;</sapn>");
            }

        }).focus(function () {
            $(this).next('.tips').show();
        }).blur(function () {
            if ($.trim($(this).val()) == "" || ($(this).attr('data-type') == 'int' && isNaN(parseInt($(this).val()))) || ($(this).attr('data-type') == 'float' && isNaN(parseFloat($(this).val())))) {
                $(this).next('.tips').addClass('tip_er').removeClass('tip_ok');
            } else {
                $(this).next('.tips').removeClass('tip_er').addClass('tip_ok');
            }
        });


        $('[name=saveall]').click(function () {
            var check = true;
            var textIndex = -1;
            $('[name=MenuName],[name=MenuIndex]').each(function (i) {
                var val = $(this).val();
                if (val.length == 0) {
                    check = false;
                    $(this).focus().blur();
                }
            });
            if (check == false) {
                alert("请检查输入");
                return false;
            }

        });

        $('[name=createwxmenu]').click(function () {
            if (confirm('确定要生成微信号菜单吗') == false) {
                return false;
            }
        });

        $('[name=deletewxmenu]').click(function () {
            if (confirm('确定要删除微信号上的当前菜单吗') == false) {
                return false;
            }
        });
    </script>
</body>
</html>
